package com.cskaoyan.gateway.controller.shopping;/*
 *@author     :zhangxiaojun
 *@date       :2021/8/2515:29
 *@description: some description
 */

import com.mall.commons.result.ResponseData;
import com.mall.commons.result.ResponseUtil;
import com.mall.shopping.IGoodsService;
import com.mall.shopping.dto.AllProductRequest;
import com.mall.shopping.dto.AllProductResponse;
import com.mall.shopping.dto.ProductResponse;
import com.mall.shopping.dto.RecommendResponse;
import com.mall.user.annotation.Anoymous;
import com.mall.user.constants.SysRetCodeConstants;
import lombok.extern.slf4j.Slf4j;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Slf4j
@RestController
@RequestMapping("/shopping")
public class GoodsController {

    @Reference(timeout = 3000,retries = 2, check = false)
    IGoodsService iGoodsService;

    @GetMapping("/goods")
    @Anoymous
    public ResponseData goods(AllProductRequest allProductRequest){
        AllProductResponse allProductResponse= iGoodsService.selectGoods(allProductRequest);
        if (allProductResponse.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())){
            ProductResponse productResponse = new ProductResponse(allProductResponse.getProductDtoList(),allProductResponse.getTotal());
            return new ResponseUtil<>().setData(productResponse);
        }
        return new ResponseUtil().setErrorMsg(allProductResponse.getMsg());
    }
    @GetMapping("/recommend")
    @Anoymous
    public ResponseData recommend(){
        RecommendResponse recommendResponse = iGoodsService.getRecommendGoods();
        if (recommendResponse.getCode().equals(SysRetCodeConstants.SUCCESS.getCode())){
            return new ResponseUtil<>().setData(recommendResponse.getPanelContentItemDtos());
        }
        return new ResponseUtil().setErrorMsg(recommendResponse.getMsg());
    }
}
